package org.datastructure.secondday.tree.threadedbinarytree;

public class ThreadedBinaryTreeDemo {
    public static void main(String[] args) {

    }
}

class ThreadedBinaryTree {
    private HeroNode root;
    private HeroNode pre;

    public void setRoot(HeroNode root) {
        this.root = root;
    }


    public void threadedList() {
        HeroNode node = root;
        while (node != null) {
            while (node.getRightType() == 0) {
                node = node.getLeft();
            }

            System.out.println(node);


            while (node.getRightType() == 1) {
                node = node.getRight();
                System.out.println(node);
            }
            node = node.getRight();
        }


    }

    public void threadedTree(HeroNode root) {
        if (root == null) {
            return;
        }


        threadedTree(root.getLeft());

        if (root.getLeft() == null) {
            root.setLeft(pre);
            root.setLeftType(1);
        }

        if (pre != null && pre.getRight() == null) {
            pre.setRight(root);
            pre.setRightType(1);
        }

        pre = root;

        threadedTree(root.getRight());
    }
}
